package com.winapi.winapiinterface.controller;

import com.winapi.winapiclientsdk.model.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author yyzhang
 * @version 1.0
 */
@RestController
@RequestMapping("/name")
@CrossOrigin(origins = {"http://winapi.winwin121.online"},allowCredentials = "true")
public class NameController {

    @GetMapping("/get")
    public String getNameByGet(String name){
        return "get:用户名字是："+name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestParam String name){
        return "post:用户名字是："+name;
    }

    /**
     * restful风格
     * @param user
     * @return
     */
    @PostMapping("/user")
    public String getUserNameByPost(@RequestBody User user, HttpServletRequest request){
//        String accessKey = request.getHeader("accessKey");
//        String sign = request.getHeader("sign");
//        String nonce = request.getHeader("nonce");
//        String timestamp = request.getHeader("timestamp");
//        String body=request.getHeader("body");
//        if(!accessKey.equals("winwin"))
//            throw new RuntimeException("无权限");
//        if(Long.parseLong(nonce)>10000){
//            throw new RuntimeException("无权限");
//        }
//        //todo:实际是从数据库中查找secretKey
//        String sign1 = SignUtils.getSign(body, "abcdefg");
//        if(!sign1.equals(sign)){
//            throw new RuntimeException("无权限");
//        }
        String result= "Post:用户名字是："+user.getUsername();
        return result;
    }
}
